package com.xy.hms.config;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiaye
 * @create 2020-03-03-8:37
 */
@Configuration
public class MyservletConfig {

    //注册三大组件，由原先的web.xml到现在在springboot中配置，加载到spring容器中

    /**
     * 这是servlet注册
     * @return
     */
    @Bean
    public ServletRegistrationBean<MyDefineServlet> servletServletRegistrationBean(){
        ServletRegistrationBean<MyDefineServlet> myDefineServletServletRegistrationBean =
                new ServletRegistrationBean<>(new MyDefineServlet(),"/myservlet");
        return myDefineServletServletRegistrationBean;
    }




    //配置嵌入式的servlet容器
//    @Bean
//    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> webServerFactoryCustomizer(){
//        return new WebServerFactoryCustomizer<TomcatServletWebServerFactory>() {
//            //定制嵌入的Servlet容器相关规则
//            @Override
//            public void customize(TomcatServletWebServerFactory factory) {
//                factory.setPort(8082);
//            }
//        };
//    }
}
